using System;
using LS.Saving;
using UnityEngine;
using Unity.VisualScripting;

namespace LS.VisualScripting
{
    public class GetBool : SavingUnit
    {
        [DoNotSerialize]
        public ValueInput Name { get; set; }
        
        [DoNotSerialize]
        public ValueInput GroupName { get; set; }
        
        [DoNotSerialize]
        public ValueOutput Value { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            Name = ValueInput<string>(nameof(Name), string.Empty);
            GroupName = ValueInput<string>(nameof(GroupName), string.Empty);
            Value = ValueOutput<bool>(nameof(Value));
            Requirement(Name, Input);
            Requirement(GroupName, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            string name =  flow.GetValue<string>(Name);
            string groupName = flow.GetValue<string>(GroupName);
            bool value = Target?.GetBool(name, groupName) ?? false;
            flow.SetValue(Value, value);
            return base.In(flow);
        }
    }
}